package com.tiancheng.onecode.task;

import com.tiancheng.onecode.service.IMemberOrderService;
import com.tiancheng.onecode.utils.DateTimeUtil;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author: kellen
 * @Description:
 * @Date: create in 2024/12/30 14:20
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class OrderVerificationTaskMy implements MyScheduledTask {

    @Resource
    private IMemberOrderService memberOrderService;
    /**
     * 订单核销
     * 每天凌晨1点核销前一天的订单
     */
    @Override
    @Scheduled(cron = "0 55 23 * * ?")
//    @Scheduled(cron = "0 30 17 * * ?")
    public void execute() {
        log.info("开始执行核销操作");
        process(() -> {
            String formatter = DateTimeUtil.formatter(LocalDateTime.now(), DateTimeUtil.bj_pattern);
            memberOrderService.verification(formatter);
        });
    }
}
